package com.uc.sdk.g3;

import com.uc.sdk.TcpClient;
import com.uc.sdk.g3.handler.G3ReadHandler;
import com.uc.sdk.g3.handler.HeartBeatHandler;
import com.uc.sdk.handler.ChannelStatusHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.bytes.ByteArrayEncoder;
import io.netty.handler.codec.string.StringDecoder;

public class G3Client extends TcpClient {

    public G3Client(String host, int port) {
        super(host, port);
    }

    public G3Client(String host) {
        super(host);
    }

    private IG3Watcher ig3Watcher;

    public G3Client watch(IG3Watcher ig3Watcher){
        this.ig3Watcher = ig3Watcher;
        return this;
    }

    @Override
    protected void initChannel(SocketChannel ch) {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new G3ReadHandler(ig3Watcher))
                .addLast(new ByteArrayEncoder())
                .addLast(new HeartBeatHandler())
                .addLast(new ChannelStatusHandler());
    }
}
